﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MaLu.Common;
using MaLu.BusiLogic;
using System.Data;
using System.Xml;

namespace MaluJg.web.Visite
{
    public partial class VisiteDetail : VisitePage1
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                BindData();
            }
        }

        private bool OutDate(string xml)
        {
            bool isountdate = false;
            if (xml.Trim() != string.Empty)
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(xml);
                XmlNode xn = doc.SelectSingleNode("//Item/问题");
                if (xn != null)
                {
                    XmlNodeList xnl = xn.ChildNodes;
                    DateTime dt = DateTime.Now;
                    DateTime dtnow = DateTime.Now;
                    foreach (XmlNode item in xnl)
                    {
                        dt = dtnow;
                        if (DateTime.TryParse(item.Attributes["p3"].Value,out dt ))
                        {
                            if (dtnow > dt)
                            {
                                isountdate = !(bool.Parse(item.Attributes["p5"].Value) || bool.Parse(item.Attributes["p6"].Value));
                                if (isountdate)
                                    break;
                            
                            }
                        }
                    }
                
                }
                return isountdate;
            }

            return isountdate;
        }
        private void BindData()
        {
            DataTable dt = BLVisite.GetVisiteDetailList(Provider, Year,Month);
           
            dt.Columns.Add("item1");
            dt.Columns.Add("item2");
            dt.Columns.Add("item3");
            dt.Columns.Add("item4");
            dt.Columns.Add("item5");
         
            foreach (DataRow item in dt.Rows)
            {
                foreach (DataColumn col in dt.Columns)
                {
                    if (col.ColumnName.StartsWith("item") && !col.ColumnName.EndsWith(".aspx"))
                    {
                        item[col.ColumnName] = "<img src=\"images/green.gif\"";
                        if (item[col.ColumnName+".aspx"].ToString() == "0")
                        {
                            item[col.ColumnName] = "<img src=\"images/gray.gif\"";
                        }
                       
                    }
                   
                }

               
            }

            foreach (DataRow item in dt.Rows)
            {
                
                foreach (DataColumn col in dt.Columns)
                {
                    
                    if (col.ColumnName.ToLower() == "item5.aspx")
                    {
                        bool isOutDate = OutDate(item["item5content"].ToString());
                        if (isOutDate)
                            item[col.ColumnName.Substring(0, 5)] = "<img src=\"images/gray.gif\"";
                    }
                }


            }
            rptProject.DataSource = dt;
            rptProject.DataBind();
        }
    }
}
